﻿using System;
using System.Data.Objects;
using System.Linq;

namespace EstateNuke.Data
{
    public partial class Alert
    {
        #region Set Processed

        /// <summary>
        /// </summary>
        /// <param name = "processedByUser"></param>
        /// <param name = "modifiedUser"></param>
        public void SetProcessed(User processedByUser, User modifiedUser)
        {
            if (processedByUser == null)
            {
                throw new ArgumentNullException("processedByUser");
            }
            if (modifiedUser == null)
            {
                throw new ArgumentNullException("modifiedUser");
            }
            if (!ProjectReference.IsLoaded)
            {
                ProjectReference.Load(MergeOption.PreserveChanges);
            }
            switch (AlertTypeId)
            {
                case 10:
                    var customerCommunicationScheduledCallbackAlert = Project.InternalCustomerCommunicationScheduledCallbackAlerts.FirstOrDefault(item => item.Id == Id);
                    if (customerCommunicationScheduledCallbackAlert != null)
                    {
                        customerCommunicationScheduledCallbackAlert.SetProcessed(processedByUser, modifiedUser);
                    }
                    break;
                case 20:
                    var smallOrderExpiredAlert = Project.InternalSmallOrderExpiredAlerts.FirstOrDefault(item => item.Id == Id);
                    if (smallOrderExpiredAlert != null)
                    {
                        smallOrderExpiredAlert.SetProcessed(processedByUser, modifiedUser);
                    }
                    break;
                case 30:
                    var largeOrderEngagedContractAlert = Project.InternalLargeOrderEngagedContractAlerts.FirstOrDefault(item => item.Id == Id);
                    if (largeOrderEngagedContractAlert != null)
                    {
                        largeOrderEngagedContractAlert.SetProcessed(processedByUser, modifiedUser);
                    }
                    break;
                case 40:
                    var contractReceiptScheduledAlert = Project.InternalContractReceiptScheduledAlerts.FirstOrDefault(item => item.Id == Id);
                    if (contractReceiptScheduledAlert != null)
                    {
                        contractReceiptScheduledAlert.SetProcessed(processedByUser, modifiedUser);
                    }
                    break;
                case 100:
                    var leaseOrderEngagedContractAlert = Project.InternalLeaseOrderEngagedContractAlerts.FirstOrDefault(item => item.Id == Id);
                    if (leaseOrderEngagedContractAlert != null)
                    {
                        leaseOrderEngagedContractAlert.SetProcessed(processedByUser, modifiedUser);
                    }
                    break;
                case 110:
                    var leaseContractReceiptScheduledAlert = Project.InternalLeaseContractReceiptScheduledAlerts.FirstOrDefault(item => item.Id == Id);
                    if (leaseContractReceiptScheduledAlert != null)
                    {
                        leaseContractReceiptScheduledAlert.SetProcessed(processedByUser, modifiedUser);
                    }
                    break;
            }
        }

        #endregion

        #region Delete

        /// <summary>
        /// </summary>
        public void Delete(User modifiedUser)
        {
            if (modifiedUser == null)
            {
                throw new ArgumentNullException("modifiedUser");
            }
            if (!ProjectReference.IsLoaded)
            {
                ProjectReference.Load(MergeOption.PreserveChanges);
            }
            switch (AlertTypeId)
            {
                case 10:
                    var customerCommunicationScheduledCallbackAlert = Project.InternalCustomerCommunicationScheduledCallbackAlerts.FirstOrDefault(item => item.Id == Id);
                    if (customerCommunicationScheduledCallbackAlert != null)
                    {
                        customerCommunicationScheduledCallbackAlert.Delete(modifiedUser);
                    }
                    break;
                case 20:
                    var smallOrderExpiredAlert = Project.InternalSmallOrderExpiredAlerts.FirstOrDefault(item => item.Id == Id);
                    if (smallOrderExpiredAlert != null)
                    {
                        smallOrderExpiredAlert.Delete(modifiedUser);
                    }
                    break;
                case 30:
                    var largeOrderEngagedContractAlert = Project.InternalLargeOrderEngagedContractAlerts.FirstOrDefault(item => item.Id == Id);
                    if (largeOrderEngagedContractAlert != null)
                    {
                        largeOrderEngagedContractAlert.Delete(modifiedUser);
                    }
                    break;
                case 40:
                    var contractReceiptScheduledAlert = Project.InternalContractReceiptScheduledAlerts.FirstOrDefault(item => item.Id == Id);
                    if (contractReceiptScheduledAlert != null)
                    {
                        contractReceiptScheduledAlert.Delete(modifiedUser);
                    }
                    break;
                case 100:
                    var leaseOrderEngagedContractAlert = Project.InternalLeaseOrderEngagedContractAlerts.FirstOrDefault(item => item.Id == Id);
                    if (leaseOrderEngagedContractAlert != null)
                    {
                        leaseOrderEngagedContractAlert.Delete(modifiedUser);
                    }
                    break;
                case 110:
                    var leaseContractReceiptScheduledAlert = Project.InternalLeaseContractReceiptScheduledAlerts.FirstOrDefault(item => item.Id == Id);
                    if (leaseContractReceiptScheduledAlert != null)
                    {
                        leaseContractReceiptScheduledAlert.Delete(modifiedUser);
                    }
                    break;
            }
        }

        /// <summary>
        /// </summary>
        public void CancelDelete(User modifiedUser)
        {
            if (modifiedUser == null)
            {
                throw new ArgumentNullException("modifiedUser");
            }
            if (!ProjectReference.IsLoaded)
            {
                ProjectReference.Load(MergeOption.PreserveChanges);
            }
            switch (AlertTypeId)
            {
                case 10:
                    var customerCommunicationScheduledCallbackAlert = Project.InternalCustomerCommunicationScheduledCallbackAlerts.FirstOrDefault(item => item.Id == Id);
                    if (customerCommunicationScheduledCallbackAlert != null)
                    {
                        customerCommunicationScheduledCallbackAlert.Delete(modifiedUser);
                    }
                    break;
                case 20:
                    var smallOrderExpiredAlert = Project.InternalSmallOrderExpiredAlerts.FirstOrDefault(item => item.Id == Id);
                    if (smallOrderExpiredAlert != null)
                    {
                        smallOrderExpiredAlert.CancelDelete(modifiedUser);
                    }
                    break;
                case 30:
                    var largeOrderEngagedContractAlert = Project.InternalLargeOrderEngagedContractAlerts.FirstOrDefault(item => item.Id == Id);
                    if (largeOrderEngagedContractAlert != null)
                    {
                        largeOrderEngagedContractAlert.CancelDelete(modifiedUser);
                    }
                    break;
                case 40:
                    var contractReceiptScheduledAlert = Project.InternalContractReceiptScheduledAlerts.FirstOrDefault(item => item.Id == Id);
                    if (contractReceiptScheduledAlert != null)
                    {
                        contractReceiptScheduledAlert.CancelDelete(modifiedUser);
                    }
                    break;
                case 100:
                    var leaseOrderEngagedContractAlert = Project.InternalLeaseOrderEngagedContractAlerts.FirstOrDefault(item => item.Id == Id);
                    if (leaseOrderEngagedContractAlert != null)
                    {
                        leaseOrderEngagedContractAlert.CancelDelete(modifiedUser);
                    }
                    break;
                case 110:
                    var leaseContractReceiptScheduledAlert = Project.InternalLeaseContractReceiptScheduledAlerts.FirstOrDefault(item => item.Id == Id);
                    if (leaseContractReceiptScheduledAlert != null)
                    {
                        leaseContractReceiptScheduledAlert.CancelDelete(modifiedUser);
                    }
                    break;
            }
        }

        #endregion
    }
}